package com.yiyuan.weixin.weixinInservice;

import com.yiyuan.weixin.Common.GlobalConstant;
import com.yiyuan.weixin.model.ReceiveXmlEntity;
import com.yiyuan.weixin.weixinInservice.Iml.WXResponsetText;
import com.yiyuan.weixin.weixinInservice.Iml.WXResposeCustomize;
import com.yiyuan.weixin.weixinInservice.service.WXResponseService;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by admin on 2017/3/24.
 */
public class WXResponseDispatcherUtil {
    /*******
     * 微信响应分配器
     * @param xmlEntity
     */
   public static void messageDispatcher(HttpServletResponse resp,ReceiveXmlEntity xmlEntity){
       WXResponseService wxRespondService=null;
       if (xmlEntity==null){
           System.out.printf("微信消息解析错误");
           return;
       }


       switch (xmlEntity.getMsgType())
       {
           case GlobalConstant.TEXT:
               wxRespondService=new WXResposeCustomize();
               break;
           case GlobalConstant.IMAGE ://= "IMAGE";
               wxRespondService=new WXResponsetText();
               break;
           case GlobalConstant.MUSIC ://= "MUSIC";
               wxRespondService=new WXResponsetText();
               break;
           case GlobalConstant.NEWS ://= "NEWS";
               wxRespondService=new WXResponsetText();
               break;
           case GlobalConstant.VIDEO ://= "VIDEO";
               wxRespondService=new WXResponsetText();
               break;
           case GlobalConstant.VOICE ://= "VOICE";
               wxRespondService=new WXResponsetText();
               break;
           case GlobalConstant.EVENT :
               WXEventDispatcherUtil.eventDispatcher(resp,xmlEntity);
               break;
           default:
       }
       if (wxRespondService!=null)
        wxRespondService.wxRespond(resp,xmlEntity);
   }
}
